<template>
  <div style="width: auto;height: 225px" id="echarts2">
  </div>
</template>

<script>
import echarts from 'echarts'
export default {
  name: 'echarts2',
  props: {
    counts: {
      type: Object,
      required: true
    }
  },
  watch: {
    counts: {
      handler: 'updateChart',
      immediate: true,
      deep: true
    }
  },
  data () {
    return {
      chart: null,
      option: {
        title: {
          text: '酒店景点占比',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: [
              { value: 0, name: '酒店' },
              { value: 0, name: '景点' }
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
    }
  },
  mounted () {
    this.chart = echarts.init(document.getElementById('echarts2'));
    this.chart.setOption(this.option);
  },
  methods: {
    updateChart() {
      if (this.counts && this.chart) {
        this.option.series[0].data = [
          { value: this.counts.hotels || 0, name: '酒店' },
          { value: this.counts.attractions || 0, name: '景点' }
        ];
        this.chart.setOption(this.option);
      }
    }
  }
}
</script>

<style scoped>
</style>
